/**
 * 智慧小区管理系统 - 物业管理模块类型定义
 * @author Wu.Liang
 * @date 2025-06-26
 * @version 3.0 - 根据系统设计调整方案重构，统一接口规范
 */

// 基础响应类型
export interface ApiResponse<T = unknown> {
  code: number
  message: string
  data: T
  success?: boolean
}

// 分页响应类型
export interface PageResponse<T = any> {
  records: T[]
  total: number
  size: number
  current: number
  pages: number
}

// 基础查询参数 - 根据新接口调整
export interface BaseQueryParams {
  current?: number
  size?: number
  communityId?: number | undefined
  buildingId?: number | undefined
  unitId?: number | undefined
  householdId?: number | undefined
  userId?: number | undefined
  paymentStatus?: number | undefined
  billingPeriod?: string | undefined
  startDate?: string | undefined
  endDate?: string | undefined
  keyword?: string | undefined
}

// 费用类型枚举
export enum FEE_TYPE {
  PROPERTY_FEE = 0,
  SANITATION_FEE = 1,
  WATER_FEE = 2,
  ELECTRICITY_FEE = 3,
  GAS_FEE = 4
}

// 物业费相关类型 - 根据新接口调整
export interface PropertyFee {
  id: string
  userId: string
  communityId: string
  householdId: string
  feeType: FEE_TYPE
  feeName: string
  billingPeriod: string
  amount: number
  paymentStatus: number
  paymentStatusName?: string
  paymentAmount: number
  dueDate: string
  paymentTime?: string
  paymentMethod?: string
  paymentMethodName?: string
  remark?: string
  createTime: string
  updateTime: string
  remainingAmount: number
  overdueDays: number
  isOverdue: boolean
  // 关联信息
  userName?: string
  communityName?: string
  buildingName?: string
  roomNumber?: string
  householdAddress?: string
}

// 卫生费相关类型 - 与后端VO对象匹配
export interface SanitationFee {
  id: string
  feeNo: string
  userId: string
  userName?: string
  communityId: string
  communityName?: string
  buildingId?: string
  buildingName?: string
  unitId?: string
  unitName?: string
  householdId: string
  roomNumber?: string
  householdAddress?: string
  billingPeriod?: string
  amount: number
  dueDate: string
  paymentStatus: number
  paymentStatusName?: string
  paymentAmount?: number
  paymentTime?: string
  remark?: string
  createTime: string
  updateTime: string
  feeType?: FEE_TYPE // 可选，部分接口可能无
}

// 燃气费相关类型 - 保持兼容
export interface GasFee {
  id: string
  feeNo: string
  householdId: string
  householdName: string
  buildingName: string
  roomNumber: string
  communityId: string
  communityName: string
  meterNumber: string
  previousReading: number
  currentReading: number
  usage: number
  unitPrice: number
  feeAmount: number
  paidAmount: number
  unpaidAmount: number
  billingMonth: string
  dueDate: string
  paymentStatus: 'UNPAID' | 'PAID' | 'PARTIAL' | 'OVERDUE'
  safetyStatus: 'NORMAL' | 'WARNING' | 'DANGER'
  paymentMethod?: string
  paymentTime?: string
  remark?: string
  createTime: string
  updateTime: string
  feeType?: FEE_TYPE // 可选，部分接口可能无
}

// 水电费相关类型 - 保持兼容
export interface UtilityFee {
  id: string
  feeNo: string
  householdId: string
  householdName: string
  buildingName: string
  roomNumber: string
  communityId: string
  communityName: string
  utilityType: 'WATER' | 'ELECTRICITY'
  meterNumber: string
  previousReading: number
  currentReading: number
  usage: number
  unitPrice: number
  feeAmount: number
  paidAmount: number
  unpaidAmount: number
  billingMonth: string
  dueDate: string
  paymentStatus: 'UNPAID' | 'PAID' | 'PARTIAL' | 'OVERDUE'
  abnormalStatus: 'NORMAL' | 'WARNING' | 'ABNORMAL'
  paymentMethod?: string
  paymentTime?: string
  remark?: string
  createTime: string
  updateTime: string
  feeType?: FEE_TYPE // 可选，部分接口可能无
}

// 表读数类型 - 保持兼容
export interface MeterReading {
  id: string
  householdId: string
  householdName: string
  buildingName: string
  roomNumber: string
  meterNumber: string
  meterType: 'WATER' | 'ELECTRICITY' | 'GAS'
  previousReading: number
  currentReading: number
  usage: number
  readingDate: string
  readerName: string
  remark?: string
  createTime: string
  updateTime: string
}

// 费用生成参数 - 根据新接口调整
export interface FeeGenerateParams {
  communityId: number
  billingMonth: string
  feeType?: number
  unitPrice?: number  // 添加单价字段，用于物业费按面积计费
  fixedAmount?: number  // 添加固定金额字段，用于物业费固定费用
}

// 批量费用生成参数 - 根据新接口调整
export interface BatchFeeGenerateParams {
  communityIds: number[]
  billingMonth: string
  feeType?: number
}

// 缴费参数 - 根据新接口调整
export interface PaymentParams {
  paymentAmount: number
  paymentMethod: string
  remark?: string
}

// 催缴参数 - 严格对齐后端字段和类型
export interface ReminderParams {
  feeId: string;
  feeType: number;
  reminderType: number;
  reminderContent: string;
  reminderTime: string;
  nextDueDate?: string;
  nextAmount?: number;
  remark?: string;
}

// 批量催缴参数 - 根据新接口调整
export interface BatchReminderParams {
  billIds: number[]
  reminderType: string
  message: string
}

// 费用统计类型 - 根据新接口调整
export interface FeeStatistics {
  totalIncome: number
  monthlyIncome: number
  paymentRate: number
  overdueRate: number
  feeTypeDistribution: {
    propertyFee: number
    sanitationFee: number
    gasFee: number
    waterFee: number
    electricityFee: number
  }
  monthlyTrend: {
    month: string
    income: number
    paymentCount: number
  }[]
  communityComparison: {
    communityName: string
    income: number
    paymentRate: number
  }[]
}

// 催缴记录类型 - 保持兼容
export interface ReminderRecord {
  id: string
  feeId: string
  feeType: number
  userId: string
  reminderType: number
  reminderStatus: number
  reminderContent: string
  reminderTime: string
  nextDueDate?: string
  nextAmount?: string
  remark?: string
  createBy?: string
  createTime?: string
  updateBy?: string
  updateTime?: string
}

// 催缴统计类型 - 保持兼容
export interface ReminderStatistics {
  totalSent: number
  successCount: number
  failedCount: number
  responseRate: number
  typeDistribution: {
    SMS: number
    EMAIL: number
    APP_PUSH: number
    PHONE: number
  }
  dailyTrend: {
    date: string
    sentCount: number
    successCount: number
  }[]
}

// 支付类型 - 保持兼容
export interface Payment {
  id: string
  orderNo: string
  billId: string
  billNo: string
  billType: 'PROPERTY_FEE' | 'SANITATION_FEE' | 'GAS_FEE' | 'WATER_FEE' | 'ELECTRICITY_FEE'
  amount: number
  paymentMethod: 'WECHAT' | 'ALIPAY' | 'BANK_CARD'
  paymentStatus: 'PENDING' | 'SUCCESS' | 'FAILED' | 'REFUNDED'
  transactionId?: string
  paymentTime?: string
  refundTime?: string
  remark?: string
  createTime: string
  updateTime: string
}

// 费用规则类型 - 保持兼容
export interface FeeRule {
  id: number
  communityId: number
  communityName: string
  feeType: string
  ruleName: string
  unitPrice: number
  calculationMethod: 'AREA' | 'PERSON' | 'USAGE' | 'FIXED'
  billingCycle: 'MONTHLY' | 'QUARTERLY' | 'YEARLY'
  effectiveDate: string
  expiryDate?: string
  status: 'ACTIVE' | 'INACTIVE'
  description?: string
  createTime: string
  updateTime: string
}

// 社区类型 - 保持兼容
export interface Community {
  id: string
  name: string
  code: string
  address: string
  contactPhone: string
  managerName: string
  status: 'ACTIVE' | 'INACTIVE'
}

export interface PropertyCompanyQueryParams extends BaseQueryParams {
  companyName?: string
  companyCode?: string
  contactPerson?: string
  contactPhone?: string
  status?: number
  auditStatus?: number
  qualificationLevel?: string
  establishedDateStart?: string
  establishedDateEnd?: string
}

export interface PropertyCompanyFormData {
  companyName: string
  companyCode: string
  businessLicense?: string
  legalRepresentative?: string
  contactPerson: string
  contactPhone: string
  contactEmail?: string
  address?: string
  establishedDate?: string
  registeredCapital?: number
  serviceScope?: string
  qualificationLevel?: string
  paymentQrCode?: string
  paymentAccount?: string
  paymentBank?: string
  paymentLink?: string
  wechatPayMerchantId?: string
  alipayMerchantId?: string
  companyLogo?: string
  introduction?: string
  businessHours?: string
  serviceHotline?: string
}

export interface PropertyCompanyAuditData {
  auditStatus: number
  auditRemark?: string
}

export interface PropertyCompanyStats {
  totalCount: number
  activeCount: number
  inactiveCount: number
  pendingAuditCount: number
  approvedCount: number
  rejectedCount: number
  qualificationLevelStats: {
    level: string
    count: number
  }[]
  monthlyGrowth: {
    month: string
    count: number
  }[]
}

export interface PropertyInfo {
  propertyCompanyId?: number
  companyName?: string
  companyCode?: string
  companyLogo?: string
  introduction?: string
  businessHours?: string
  serviceHotline?: string
  contactPerson?: string
  contactPhone?: string
  contactEmail?: string
  address?: string
  establishedDate?: string
  registeredCapital?: number
  serviceScope?: string
  qualificationLevel?: string
  paymentQrCode?: string
  paymentAccount?: string
  paymentBank?: string
  paymentLink?: string
  wechatPayMerchantId?: string
  alipayMerchantId?: string
} 